
import java.io.IOException;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class PlayerMIDI implements Runnable {
	private static Player musicPlayer;

	public PlayerMIDI(String musica) throws IOException, MediaException {
		PlayerMIDI.musicPlayer = Manager.createPlayer(
				getClass().getResourceAsStream(musica), "audio/midi");

		PlayerMIDI.musicPlayer.realize();
		PlayerMIDI.musicPlayer.prefetch();
	}

	public void run() {
		try {
			PlayerMIDI.play();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}
	
	public static void play() throws MediaException{
		PlayerMIDI.musicPlayer.start();
	}
	
	public static void stop() throws MediaException{
		PlayerMIDI.musicPlayer.stop();
	}
	
	public static long getTime(){
		return PlayerMIDI.musicPlayer.getMediaTime()/1000;
	}
}
